<?xml version="1.0" encoding="UTF-8" ?>
 
<xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns="http://www.w3.org/1999/xhtml">
    <xsl:output method="xml" indent="no"
        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

<xsl:include href="../../../templates/popup.xsl"/>

<xsl:template match="*"/>

<xsl:template match="report_name">
    <h1><xsl:value-of select="."/></h1>
</xsl:template>

<xsl:template match="incomplete">
    <div style="text-align: center; font-weight: bold;">!!! Детальная статистика работы роботов сохранена за период с <xsl:value-of select="@minDate"/> по <xsl:value-of select="@maxDate"/> !!!</div>
</xsl:template>

<xsl:template match="empty">
    <div style="text-align: center; font-weight: bold;">!!! Детальная статистика работы роботов отсутствует !!!</div>
</xsl:template>

<xsl:template match="report_data">
    <script type="text/javascript">
        <xsl:comment>
        <![CDATA[
        function openPopup(a)
        {
            var win = window.open();
            win.document.location.href=a.href;
            return false;
        }
        ]]> 
        </xsl:comment>
    </script>
    <table id="reportTable" class="reportTable">
    <tr><th>Время</th><th>Запрос</th></tr>
    <xsl:apply-templates select="row"/>
    </table>
</xsl:template>


<xsl:template match="row">
    <tr>
        <td><xsl:value-of select="@date"/><xsl:text> </xsl:text><xsl:value-of select="@time"/></td>
        <td style="text-align: left;"><a href="{@url}" target="_blank" onclick="return openPopup(this);" class="external"><xsl:value-of select="@urlHuman"/></a></td>
    </tr>
</xsl:template>


<xsl:template match="report_data_more">
    <div align="center"><input type="button" onclick="showMore();" id="showMoreButton" value="Показать ещё"/></div>
    <input type="hidden" id="showMoreDate1" value="{/root/date1}"/>
    <input type="hidden" id="showMoreDate2" value="{/root/date2}"/>
    <input type="hidden" id="showMoreRobot" value="{@robot}"/>
    <input type="hidden" id="showMoreStart" value="{@start}"/>
    <input type="hidden" id="showMoreCount" value="{@count}"/>
    <script src="design/append_table.js" type="text/javascript"/>
    <script src="design/httprequest.js" type="text/javascript"/>
    <script type="text/javascript">
        <xsl:comment>
        <![CDATA[
        function onData(data)
        {
            from = data.getElementsByTagName('table');
            to = document.getElementById('reportTable');
            if (from.length > 0 && to) {
                var count = appendTable(from.item(0), to);
                document.getElementById('showMoreStart').value = parseInt(document.getElementById('showMoreStart').value) + count;
                if (count >= document.getElementById('showMoreCount').value)
                    document.getElementById('showMoreButton').disabled = false;
                else
                    document.getElementById('showMoreButton').value = 'Всё закончилось.';
            }
        }
        function onError(text)
        {
            document.getElementById('showMoreButton').disabled = false;
            alert(text);
        }
        function showMore(){
            document.getElementById('showMoreButton').disabled = true;
            var params = 'module=robots&report=detail_more';
            params += '&date1='+document.getElementById('showMoreDate1').value;
            params += '&date2='+document.getElementById('showMoreDate2').value;
            params += '&robot='+document.getElementById('showMoreRobot').value;
            params += '&start='+document.getElementById('showMoreStart').value;
            params += '&count='+document.getElementById('showMoreCount').value;
            httpRequest('report.php', params, onData, onError, {'asHTML': true});
        }
        ]]> 
        </xsl:comment>
    </script>
</xsl:template>

</xsl:stylesheet>